package Help.For.You.member.Impl;

import javax.annotation.Resource;
import javax.servlet.http.HttpSession;


import org.apache.log4j.Logger;
import org.springframework.stereotype.Service;
import org.springframework.ui.Model;

import Help.For.You.Other.PageVO;
import Help.For.You.member.MemberVO;

@Service(value = "MemberService")
public class MemberService {
	
	@Resource(name ="MemberDao")
	private MemberDao memberDao;
	
	private Logger logger=Logger.getLogger(this.getClass());
	
	/*로그인화면띄우기*/
	public String GetViewLogin(PageVO pageVO,HttpSession session,Model model){
		logger.info("GetViewLogin");
		
		String PAGE_NAXT="";		
		PAGE_NAXT = pageVO.getPAGE_NEXT();
		pageVO.changeSuccsesPage();
		model.addAttribute("pageVO", pageVO);
		return PAGE_NAXT;
	}
	
	
	/*로그인 처리*/		
	public String PostActionLogin(MemberVO memberVO,PageVO pageVO,HttpSession session,Model model) {
		logger.info("PostActionLogin");
		
		String PAGE_NAXT="";
		MemberVO reMemberVO = memberDao.PostActionLogin(memberVO);
		
		if(reMemberVO!=null){
			if(reMemberVO.getMEMBER_CONDITION().equals("Y")){
				session.setAttribute("SESSION_ID",reMemberVO.getMEMBER_ID());
				session.setAttribute("SESSION_DIVISION",reMemberVO.getMEMBER_DIVISION());
				if(pageVO.getPAGE_CHECK()==0){
					PAGE_NAXT=pageVO.getPAGE_NEXT();
					
				}else{
					PAGE_NAXT=pageVO.getPAGE_ORIGINALLY();				
				}
				pageVO.changeSuccsesPage();
			}else if(reMemberVO.getMEMBER_CONDITION().equals("N")){
				//다시디비연결해서 비활성화 이유
				PAGE_NAXT=pageVO.getPAGE_NOW();
				model.addAttribute("Login_msg","비활성화 이유");
			}else{
				//탈퇴된상태
				PAGE_NAXT=pageVO.getPAGE_NOW();
				model.addAttribute("Login_msg","탈퇴회원입니다");
			}
		}else{
			PAGE_NAXT=pageVO.getPAGE_NOW();
			model.addAttribute("Login_msg","ID/PW를 확인하세요");
		}
		
		model.addAttribute("pageVO", pageVO);
		return PAGE_NAXT;
	}
}
